package utils

import (
	"fmt"
	"math/cmplx"
)

func NpDot(x, y []complex128) (r complex128, err error) {
	if len(x) != len(y) {
		err = fmt.Errorf("mismatch size,[x]=%d,[y]=%d", len(x), len(y))
		return
	}
	for i, v := range x {
		r += v * cmplx.Conj(y[i])
	}
	return
}

func CycleShift(D []complex128, s int) []complex128 {
	l := len(D)
	fd := make([]complex128, l)
	if s > 0 {
		copy(fd[s:], D[:l-s])
		copy(fd[:s], D[l-s:])
	} else if s < 0 {
		copy(fd[l+s:], D[:-s])
		copy(fd[:l+s], D[-s:])
	} else {
		copy(fd, D)
	}
	return fd
}

func NpDotCF(x []complex128, y []float64) (s complex128) {
	for i, v := range x {
		s += v * complex(y[i], 0.0)
	}
	return
}
